home *** CD-ROM | disk | FTP | other *** search
- unit Lightchk;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TLightCheck = class(TCustomControl)
- private
- PFState: TCheckBoxState;
- FOnColor,
- FOffColor : TColor;
- function GetChecked: Boolean;
- procedure SetChecked(Value: Boolean);
- procedure SetOnColor(Value: TColor);
- procedure SetOffColor(Value: TColor);
- protected
- procedure Paint; override;
- procedure Toggle; virtual;
- procedure Click; override;
- public
- constructor Create(aOwner: TComponent); override;
- procedure CreateParams(var Params: TCreateParams); override;
- property State: TCheckBoxState read PFState;
- published
- property Checked: Boolean read GetChecked write SetChecked;
- property OnColor: TColor read FOnColor write SetOnColor default clLime;
- property OffColor: TColor read FOffColor write SetOffColor default clRed;
- property OnClick;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnEnter;
- property OnExit;
- property OnKeyPress;
- property OnKeyDown;
- property OnKeyUp;
- end;
-
-
-
- procedure Register;
-
-
-
- implementation
-
- uses
- ExtCtrls;
-
-
- constructor TLightCheck.Create;
- begin
- inherited Create(aOwner);
- ControlStyle := [csCaptureMouse, csClickEvents, csDesignInteractive];
- FOnColor := clLime;
- FOffColor := clRed;
- Width := 7;
- Height := 7;
- end;
-
-
- procedure TLightCheck.CreateParams(var Params: TCreateParams);
- begin
- { call the create of the params }
- inherited CreateParams(Params);
- { and then add our twist, transparency }
- Params.ExStyle := Params.ExStyle + WS_EX_Transparent;
- end;
-
-
-
- procedure TLightCheck.Paint;
- var
- X,
- Y : Integer;
- TheColor : TColor;
- begin
- X := (Width div 2) - 3;
- Y := (Height div 2) - 3;
-
- if Checked then
- TheColor := FOnColor
- else
- TheColor := FOffColor;
-
- with Canvas do
- begin
- { 7x7 }
- Pixels[X+2, Y] := clBtnShadow;
- Pixels[X+3, Y] := clBtnShadow;
- Pixels[X+4, Y] := clBtnShadow;
- Pixels[X+1, Y+1] := clBtnShadow;
- Pixels[X, Y+2] := clBtnShadow;
- Pixels[X, Y+3] := clBtnShadow;
- Pixels[X, Y+4] := clBtnShadow;
- Pixels[X+1, Y+5] := clBtnShadow;
-
- Pixels[X+6, Y+2] := clBtnHighLight;
- Pixels[X+6, Y+3] := clBtnHighLight;
- Pixels[X+6, Y+4] := clBtnHighLight;
- Pixels[X+5, Y+1] := clBtnHighLight;
- Pixels[X+2, Y+6] := clBtnHighLight;
- Pixels[X+3, Y+6] := clBtnHighLight;
- Pixels[X+4, Y+6] := clBtnHighLight;
- Pixels[X+5, Y+5] := clBtnHighLight;
- Pixels[X+2, Y+3] := clBtnHighLight;
-
- Pixels[X+2, Y+1] := TheColor;
- Pixels[X+3, Y+1] := TheColor;
- Pixels[X+4, Y+1] := TheColor;
- Pixels[X+1, Y+2] := TheColor;
- Pixels[X+2, Y+2] := TheColor;
- Pixels[X+3, Y+2] := TheColor;
- Pixels[X+4, Y+2] := TheColor;
- Pixels[X+5, Y+2] := TheColor;
- Pixels[X+1, Y+3] := TheColor;
- Pixels[X+3, Y+3] := TheColor;
- Pixels[X+4, Y+3] := TheColor;
- Pixels[X+5, Y+3] := TheColor;
- Pixels[X+1, Y+4] := TheColor;
- Pixels[X+2, Y+4] := TheColor;
- Pixels[X+3, Y+4] := TheColor;
- Pixels[X+4, Y+4] := TheColor;
- Pixels[X+5, Y+4] := TheColor;
- Pixels[X+2, Y+5] := TheColor;
- Pixels[X+3, Y+5] := TheColor;
- Pixels[X+4, Y+5] := TheColor;
- { 7x7 }
- end;
- end;
-
-
- function TLightCheck.GetChecked;
- begin
- Result := not(State = cbUnChecked);
- end;
-
-
- procedure TLightCheck.SetChecked;
- begin
- if Value then
- PFState := cbChecked
- else
- PFState := cbUnChecked;
-
- Paint;
- end;
-
-
- procedure TLightCheck.Toggle;
- begin
- Checked := not Checked;
- end;
-
-
- procedure TLightCheck.Click;
- begin
- Toggle;
- end;
-
-
- procedure TLightCheck.SetOnColor;
- begin
- FOnColor := Value;
- if Checked then
- Paint;
- end;
-
-
- procedure TLightCheck.SetOffColor;
- begin
- FOffColor := Value;
- if not Checked then
- Paint;
- end;
-
-
-
-
-
-
- procedure Register;
- begin
- RegisterComponents('Standard', [TLightCheck]);
- end;
-
- end.
-